package com.example.util;

import vn.clevernet.android.sdk.ClevernetView;
import vn.sunnet.util.ads.QplayAdView;
import vn.sunnet.util.ads.QplayAdView.WidgetSize;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.example.atools.MyConstant;

public class AdsClass {
	private Activity activity = null;
	private RelativeLayout lnAdSunNet;
	public AdsClass(final Activity activity, RelativeLayout lnAdSunNet, final String __h, final String __v) {
		this.activity=activity;
		this.lnAdSunNet=lnAdSunNet;
		switch (MyConstant.mAdStatus) {
		case 1:
			addClevernetAds(__h, __v);
			break;
		case 2:
			addMobGoogle(__h, __v);
			break;
		case 3:
			addSunetAds(__h, __v);
			break;
		default:
			addClevernetAds(__h, __v);
			break;
		}
	}

	private RelativeLayout createLayout(View obj, String __h, String __v) {
		// Dung cho quang cao khong co layout
		//RelativeLayout lnAd = new RelativeLayout(activity);
		RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
				LinearLayout.LayoutParams.WRAP_CONTENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		
		
		
		
		
		if(__h.equals("1")){
			lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		}else{
			lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		}
		if(__v.equals("0")){
			lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
		}else if(__v.equals("1")){
			lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		}else{
			lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		}
		//lnAd.addView(obj, lp);// adView=quang cao cua minh
		//activity.addContentView(lnAd, new ViewGroup.LayoutParams(-1, -1));
		
		lnAdSunNet.addView(obj, lp);
		return lnAdSunNet;
	}
	private void addMobGoogle(String __h, String __v) {
		AdView adView1 = new AdView(activity, AdSize.BANNER, "a1524505255c5f8");
		createLayout(adView1, __h, __v);
		adView1.loadAd(new AdReque);
	}

	// Add Ads
	private void addSunetAds(String __h, String __v) {
		QplayAdView adView2 = new QplayAdView(activity);
		createLayout(adView2, __h, __v);
		if (adView2 != null) {
			adView2.loadAd(WidgetSize.SMALL);
		}
	}

	// Clevenet
	private void addClevernetAds(String __h, String __v) {
		ClevernetView.setAge("15-30");
		ClevernetView.setGender(ClevernetView.GENDER_MALE);
		ClevernetView adView3 = new ClevernetView(activity);
		createLayout(adView3, __h, __v);
	}
}
